package com.siki.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class WebUtils {

    public static final String CAS_URL = "https://cas.dgut.edu.cn/home/Oauth/getToken/appid/gmw/state/2020gqzx";
    public static final String Verification_User_URL = "http://gmw.dgut.edu.cn/api/center/public/index.php/index/index/checkLogin";
    public static final String DTWU_URL="http://dtwu.club/zx-form/";
    public static final String DTWU_JUMP_URL="http://dtwu.club/jump.html";

    public static JSONObject sendPostWithJson(String url, Object token) {
        String http_Return_Message_String = "";
        JSONObject http_Return_Message_Json;
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        try {
            HttpPost http_Post_Request = new HttpPost(url);
            http_Post_Request.addHeader("Content-Type", "application/json;charset=UTF-8");
            StringEntity http_Request_Body_StringEntity = new StringEntity(token.toString(), "UTF-8");
            http_Post_Request.setEntity(http_Request_Body_StringEntity);
            try {
                HttpResponse http_Response_Result = httpClient.execute(http_Post_Request);
                HttpEntity http_Response_Body = http_Response_Result.getEntity();
                http_Return_Message_String = EntityUtils.toString(http_Response_Body, "UTF-8");
                http_Return_Message_Json = JSONObject.parseObject(http_Return_Message_String);
                return http_Return_Message_Json;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
